package cn.dujc.superkid.adapter;

import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.dujc.core.util.TextColorBuilder;
import cn.dujc.core.util.ToastUtil;
import cn.dujc.superkid.R;
import cn.dujc.superkid.activities.CourseDetailActivity;
import cn.dujc.superkid.activities.CourseSelectionDetailActivity;
import cn.dujc.superkid.activities.CourseVideoActivity;
import cn.dujc.superkid.activities.MainActivity;
import cn.dujc.superkid.activities.MyTestResultsActivity;
import cn.dujc.superkid.bean.CourseEntity;
import cn.dujc.superkid.utils.ImageLoadHelper;

public class ResultAdapter extends RecyclerView.Adapter<ResultAdapter.ViewHolder>{
    private List<CourseEntity> list = new ArrayList<>();
    private TextView onetitle;
    private ImageView imageView;
    private TextView details;

    public ResultAdapter(List<CourseEntity> list) {
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_course, parent, false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        if (holder!=null) {
            holder.item_tv_couse_title.setText(list.get(position).getTitle());
            ImageLoadHelper.loadImage(holder.item_iv_couse_image,list.get(position).getCover());
            holder.item_tv_couse_info.setText(Html.fromHtml("共<font color='#ff0000'>"+list.get(position).getCourse_num()+"</font>节，已有<font color='#ff0000'>"+list.get(position).getStudy_num()+"</font>名学生学习"));
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ToastUtil.showToast(v.getContext(),list.get(position).getId());
                    Intent in = new Intent();
                    in.setClass(v.getContext(), CourseDetailActivity.class);
                    in.putExtra("course_id", list.get(position).getId());
                    in.putExtra("title",list.get(position).getTitle());
                    in.putExtra("EXTRA_COURSE",list.get(position));
                    v.getContext().startActivity(in);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView item_tv_couse_title;
        private ImageView item_iv_couse_image;
        private TextView item_tv_couse_info;
        public ViewHolder(View itemView) {
            super(itemView);
            item_tv_couse_title = itemView.findViewById(R.id.item_tv_couse_title);
            item_iv_couse_image = itemView.findViewById(R.id.item_iv_couse_image);
            item_tv_couse_info = itemView.findViewById(R.id.item_tv_couse_info);
        }
    }
}
